<%@ page contentType="text/html;charset=UTF-8" %>
<%@include file="../../common/sessionValidate.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
<head>
    <title>T_data_dic信息维护</title>
    <%@ include file="../../common/meta.jsp" %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen" id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
</head>
<style>
    hr {
        margin-top: 1px;
        border-bottom: 1px solid #1BBC9B;
    }
</style>
<body>
<form class="form-horizontal form-bordered form-row-strippe" name="ffAdd" id="ffAdd" mentod="post" role="form"
      data-toggle="validator" enctype="multipart/form-data">
    <div class="" style="margin-right:2px;padding-right:1px;">

        <!-------------------------- 面板  start--------------------------------->
        <div class="panel panel-primary">
            <div class="panel-heading clearfix" id="addHeaderDiv">
            </div>
            <div class="panel-body">
                <div class="row">
                    <h5>&nbsp;&nbsp;基本信息</h5>
                    <hr>
                    <div class="col-md-6"><!--start 换列-->
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="control-label col-md-3">主键</label>
                                <div class="col-md-9">
                                    <input id="id" name="id" type="text" class="form-control" placeholder="id"
                                           readonly="true" placeholder="自动生成，无需填写"/>
                                    <input id="data_group" name="data_group" type="hidden" value="company"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="control-label col-md-3">企业标签编码</label>
                                <div class="col-md-9">
                                    <input id="data_no" name="data_no" type="text" class="form-control"
                                           placeholder=""/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="control-label col-md-3">企业标签名称</label>
                                <div class="col-md-9">
                                    <input id="data_name" name="data_name" type="text" class="form-control"
                                           placeholder=""/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <!--如果输入元素是奇数个元素，在n=size/2?int时输出2列格式；如果元素是奇数个，需要在n=size/2?int+1时输出2列格式；需要换列，每行最多显示2列-->
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="control-label col-md-3">组名称</label>
                                <div class="col-md-9">
                                    <input id="data_type_name" name="data_type_name" value="企业标签编码" type="text"
                                           class="form-control" placeholder="企业标签编码" readonly="true"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="control-label col-md-3">显示顺序</label>
                                <div class="col-md-9">
                                    <input id="show_seq" name="show_seq" type="text" class="form-control"
                                           placeholder="请填写整数数字"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="control-label col-md-3"> 状态 </label>
                                <div class="col-md-9">
                                    <select name="flag" id="flag" class="form-control">
                                        <option value="1">有效</option>
                                        <option value="0">无效</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div><!--end 换列-->
                </div><!--end row-->
            </div><!--end body-->

            <div class="modal-footer bg-info " id='buttonDiv'>
            </div>
        </div>
        <!--------------------------面板 end------------------------------------>

    </div>
</form>
</body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js"></script>
<script src="<%= basePath %>js/calendar.js"></script>
<script type="text/javascript">
    //新增保存数据
    function add() {
        $("#addSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_data_dic/saveT_data_dic?time=" + Math.random();
        var postData = $("#ffAdd").serializeArray();
        //alert(postData);
        $.post(url, postData, function (data) {
            //var data = $.parseJSON(data);
            if (data.result == "success") {
                //保存成功  1.关闭弹出层，
                showSuccessTips("恭喜保存成功!", "提示");
                history.goBack();
            } else {
                $("#addSaveButton").removeAttr("disabled");
                showErrorTips("保存数据失败!", "错误信息：" + data.info);
                return false;
            }
        }).error(function () {
            $("#addSaveButton").removeAttr("disabled");
            showErrorTips("保存数据失败!", "错误信息：");
        });
    }

    //更新修改数据到后台
    function edit() {
        $("#editSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_data_dic/updateT_data_dic?time=" + Math.random();
        myEdit2(url);
    }

    //初始化页面及校验
    $().ready(function () {
        //1、初始化数据显示
        var name = "企业编码";
        var optype = '<%=request.getParameter("oplx")%>';
        var id = '<%=request.getParameter("id")%>';
        //alert("optype="+optype+";id="+id);
        if (optype == 'add') {
            $("#ffAdd")[0].reset();/*重置表单*/
            var basePath = "<i class='icon-plus'></i>&nbsp;";
            setHeader2("新增" + name, basePath);//设置addHeaderDiv标题文字及按钮
            setButtonDivAdd2();//设置adddiv的 操作按钮
        } else if (optype == 'edit') {
            var basePath = "<i class='icon-pencil'></i>&nbsp;";
            setHeader2("修改" + name, basePath);//设置addHeaderDiv标题文字及按钮
            setButtonDivEdit2();//设置adddiv的 操作按钮
            var url = "<%=basePath%>t_data_dic/getT_data_dic?id=" + id + "&time=" + Math.random();
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                setValue(data);
                //alert($("#effect_date").val()+""+jsonDateFormat($("#effect_date").val()));
                //$("#effect_date").val(jsonDateFormat($("#effect_date").val())); //重新设置日期类型的值
            });
        } else if (optype == 'view') {
            var basePath = "<i class='icon-eye-open'></i>&nbsp;";//设置addHeaderDiv标题文字及按钮
            setHeader2("查看" + name, basePath);
            setButtonDivView2();//设置adddiv的 操作按钮
            var url = "<%=basePath%>t_data_dic/getT_data_dic?id=" + id + "&time=" + Math.random();
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                setValue(data);
                //alert($("#effect_date").val()+""+jsonDateFormat($("#effect_date").val()));
                //$("#effect_date").val(jsonDateFormat($("#effect_date").val())); //重新设置日期类型的值
            });
            formReadOnly('ffAdd');//设置表单不可修改
        }

        //2、校验脚本初始化，start check
        $("#ffAdd").validate({
            submitHandler: function (form) {
                //alert($("#opType").val());
                if ($("#opType").val() == "add") {
                    add();
                } else if ($("#opType").val() == "edit") {
                    edit();
                }
            },
            rules: {
                id: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 22
                },
                data_type_no: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 22
                },
                data_no: {
                    //required: true,
                    maxlength: 20
                },
                data_type_name: {
                    //required: true,
                    maxlength: 60
                },
                data_no_len: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 22
                },
                data_name: {
                    //required: true,
                    maxlength: 150
                },
                limit_flag: {
                    //required: true,
                    maxlength: 1
                },
                high_limit: {
                    //required: true,
                    maxlength: 20
                },
                low_limit: {
                    //required: true,
                    maxlength: 20
                },
                effect_date: {
                    //required: true,
                    dateISO: true
                },
                expire_date: {
                    //required: true,
                    dateISO: true
                },
                timestamps: {
                    //required: true,
                    maxlength: 11
                },
                miscflgs: {
                    //required: true,
                    maxlength: 20
                },
                show_seq: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 22
                },
                flag: {
                    //required: true,
                    maxlength: 1
                }
            }, //end rules;
            messages: {
                id: {
                    //required: "主键不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>主键最大支持22位，输入的数据已经超过最大长度！</font>"
                },
                data_type_no: {
                    //required: " data_type_no不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> data_type_no最大支持22位，输入的数据已经超过最大长度！</font>"
                },
                data_no: {
                    maxlength: "<font color='red'>数据编码最大支持20位,输入的数据已经超过最大长度！</font>"
                },
                data_type_name: {
                    maxlength: "<font color='red'> data_type_name最大支持60位,输入的数据已经超过最大长度！</font>"
                },
                data_no_len: {
                    //required: " data_no_len不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> data_no_len最大支持22位，输入的数据已经超过最大长度！</font>"
                },
                data_name: {
                    maxlength: "<font color='red'>数据内容最大支持150位,输入的数据已经超过最大长度！</font>"
                },
                limit_flag: {
                    maxlength: "<font color='red'> limit_flag最大支持1位,输入的数据已经超过最大长度！</font>"
                },
                high_limit: {
                    maxlength: "<font color='red'>上限最大支持20位,输入的数据已经超过最大长度！</font>"
                },
                low_limit: {
                    maxlength: "<font color='red'>下限最大支持20位,输入的数据已经超过最大长度！</font>"
                },
                effect_date: {
                    //required: true,
                    date: "<font color='red'>请输入合法日期类型数字！</font>"
                },
                expire_date: {
                    //required: true,
                    date: "<font color='red'>请输入合法日期类型数字！</font>"
                },
                timestamps: {
                    maxlength: "<font color='red'>时间戳最大支持11位,输入的数据已经超过最大长度！</font>"
                },
                miscflgs: {
                    maxlength: "<font color='red'>扩展标识最大支持20位,输入的数据已经超过最大长度！</font>"
                },
                show_seq: {
                    //required: "显示顺序不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>显示顺序最大支持22位，输入的数据已经超过最大长度！</font>"
                },
                flag: {
                    maxlength: "<font color='red'> flag最大支持1位,输入的数据已经超过最大长度！</font>"
                }
            } //end message;
        }); //end validate;
    }) //end funciton read;
</script>
